package com.linkwin.appupdater;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;

import androidx.appcompat.app.AppCompatActivity;

import com.linkwin.updater.AppCheck;
import com.linkwin.updater.AppUpdater;
import com.linkwin.updater.UpdaterStyle;
import com.winsafe.libs.utils.UpdaterAppBaseUtil;

/**
 * Created by yandong on 2025/8/10.
 */
public class MainActivity extends AppCompatActivity {

    public final static String APP_CODE = "linkwinUpdater";
    private String mDownloadUrl = "https://apphub.linkwin.com/ProjectApi/DownloadVersion?projectCode=" + APP_CODE;
    private String mCheckUrl = "https://apphub.linkwin.com/ProjectApi/CheckVersion?projectCode=" + APP_CODE + "&version=";

    private RadioGroup radio_group;

    private AppUpdater mAppUpdater;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        radio_group = findViewById(R.id.radio_group);

    }

    public Context getContext() {
        return this;
    }

    private void clickCancel() {
        if (mAppUpdater != null) {
            mAppUpdater.stop();
        }
    }

    private void clickCheck() {
        UpdaterStyle style = UpdaterStyle.ONE_KEY_BACKEND;
        int id = radio_group.getCheckedRadioButtonId();
        switch (id) {
            case R.id.btn0:
                style = UpdaterStyle.ONE_KEY_BACKEND;
                break;
            case R.id.btn1:
                style = UpdaterStyle.ONE_KEY_BANNER;
                break;
            case R.id.btn2:
                style = UpdaterStyle.ONE_KEY_CALLBACK;
                break;
            case R.id.btn3:
                style = UpdaterStyle.ALERT_CALLBACK;
                break;
            case R.id.btn4:
                style = UpdaterStyle.DIALOG_CALLBACK;
                break;
            case R.id.btn5:
                style = UpdaterStyle.CUSTOM_CALLBACK;
                break;
        }

        AppCheck appUpdate = new AppCheck(this, mCheckUrl + UpdaterAppBaseUtil.getInstance().getAppVersionName(this), mDownloadUrl, UpdaterStyle.CUSTOM_CALLBACK, true, false);
        appUpdate.checkNewVersion();
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnCancel:
                clickCancel();
                break;
            case R.id.btnCheck:
                clickCheck();
                break;
        }
    }
}